// pages/deposit/deposit.js
import request from "../../utils/request";
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    loginShow: false,
    depositSubject: "",
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getDataLsit();
  },
  async getDataLsit() {
    const proxyId = wx.getStorageSync("proxyId");
    const res = await request({
      url:
        app.globalData.baseURL +
        `/app-api/package/out-money/page?pageNo=${1}&pageSize=${50}&proxyId=${proxyId}`,
      method: "GET",
    });
    const list = res.data.list;
    const item = list.map((item) => {
      let data = new Date(item.createTime);
      let year = data.getFullYear();
      let month = (data.getMonth() + 1).toString().padStart(2, "0");
      let day = data.getDate().toString().padStart(2, "0");
      let formattedDateTime = `${year}-${month}-${day}`;
      item.createTime = formattedDateTime;
      item.price = (item.price / 100).toFixed(2);
      return item;
    });
    this.setData({
      dataList: item,
    });
  },
  goback() {
    wx.navigateTo({
      url: `/pages/workbench/workbench?get=1`,
    })
  },
  async depositCancel(event) {
    const data = event.currentTarget.dataset.item;
    wx.showModal({
      title: "提示",
      content: "您确定要撤销该申请吗？",
      cancelText: "确定",
      confirmText: "取消",
      cancelColor: "#ff0000",
      complete: (res) => {
        if (res.cancel) {
          this.cancelOrder(data);
        }
        if (res.confirm) {
          console.log("用户点击取消");
        }
      },
    });
  },
  async cancelOrder(data) {
    const res = await request({
      url: app.globalData.baseURL + "/app-api/package/out-money/update",
      method: "PUT",
      data: {
        id: data.id,
        applyStatus: 3,
      },
    });
    if (res.code === 0) {
      wx.showToast({
        title: "撤销成功",
        icon: "success",
      });
      this.getDataLsit();
    } else {
      wx.showToast({
        title: res.msg,
        icon: "none",
      });
    }
  },
  openSubject(event) {
    this.setData({
      loginShow: true,
      depositSubject: event.currentTarget.dataset.item.subject,
    });
  },
  onCloseLogin() {
    this.setData({
      loginShow: false,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
